<template>
    <div style="position: relative;height: 100%;">
        <Table border :columns="columns" :data="datalist" :loading="tableload"></Table>
        <br/>
        <Button type="primary" :disabled="adddis" @click="addSilde">添加</Button>
        <orh-sidebar v-model="show" :title="pageTitle" cover slot="others">
            <component :is="'Operation'"  :infoId="infoId" :user_id="user_id" @showParent="showParent=>show=showParent" @expandback="expandback"></component>
        </orh-sidebar>
    </div>
</template>
<script>
    export default {
        props: {
            infoOld: {
                type: [Boolean,Number,Object,Array],
                default: false
            },
            typeother: {
                type: [Boolean,String],
                default: false
            }
        },
        components: {
            Operation: resolve => {require(['./Operation.vue'], resolve);},
        }, 
        data () {
            return {
                columns: [
                    {
                        title: '入学年份',
                        key: 'start_year',
                    },
                    {
                        title: '照顾分',
                        key: 'take_care_score'
                    },
                    {
                        title: '特长得分',
                        key: 'specialty_score'
                    },
                    {
                        title: '总分（含照顾分）',
                        key: 'total_score'
                    },
                    {
                        title: '志愿',
                        key: 'enrollments_name'
                    },
                   
                    {
                        title: '操作',
                        key: 'operation',
                        align: 'center',
                        render: (h, params) => {
                            let dis=params.row.shenhe = 2 ? false : true
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small',
                                    disabled:dis
                                },
                                style: {
                                    marginRight: '5px',
                                },
                                on: {
                                    click: () => {
                                    this.update(params.row.junior_course_id)
                                    }
                                }
                            }, '编辑'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small',
                                    disabled:dis
                                },
                                style: {
                                    marginRight: '5px',
                                },
                                on: {
                                    click: () => {
                                        this.del = params.row.junior_course_id
                                        this.confirm()
                                    }
                                }
                            }, '删除'),
                        ]);
                        }
                    }
                ],

                pageTitle:'',//右边页面的title
                show:false,//右边页面的显示隐藏

                datalist: [],
                tableload:true,
                del:null,//删除

                infoId: null,
                user_id: this.infoOld.user_id,
                adddis:true//添加按钮是否可点
            }
        },
        methods: {

            /************************************************************
             * 
             * 执行删除操作
             * 
             ************************************************************/
            confirm () {
                this.$Modal.confirm({
                    title: '数据删除',
                    content: '<p>您确定要删除这些数据吗?</p>',
                    onOk: () => {
                        if(this.del.length==0){
                            this.$Message.error('请选择删除项');
                            return
                        }
                        this.tableload = true 
                        this.$http.delete(`api/student/v1/juniorcourse/delete/${this.del}`)
                        .then(val=>{  
                            this.del=null
                            this.queryData()    
                            this.$Message.success(val.message);           
                        })
                        .catch(err=>{
                            if(err.code && err.code==422) {
                                this.$Message.error(err.message);
                            }
                            this.del=null
                            this.tableload = false 
                        })
                    },
                });
            },

            /************************************************************
             * 
             * 请求列表数据
             * 
             ************************************************************/
            queryData(){
                this.tableload=true
                this.datalist=[]
                this.$http.get('api/student/v1/juniorcourse/user_junior_info?user_id='+this.infoOld.user_id).then(val=>{
                    let obj=val.data
                    this.datalist.push(obj)

                    this.tableload=false
                }).catch(err => {
                    if(err.code && err.code==422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload=false
                });
            },

            /************************************************************
             * 
             * 点击添加
             * 
             ************************************************************/
            addSilde () {
                this.show=true
                this.infoId = false
                this.pageTitle='添加'
            },

            /************************************************************
             * 
             * 点击编辑
             * 
             ************************************************************/
            update(index){  
                this.infoId = index
                this.show=true
                this.pageTitle='修改'
            },

            /************************************************************
             * 
             * 修改添加返回数据更新
             * 
             ************************************************************/
            expandback(val){      
                if(val == true){
                    this.show=false
                    this.queryData();
                }
            },   
        },
        mounted(){
            this.queryData()
        }
    }
</script>
<style lang="less">
.ivu-table{
    height: auto;
}
</style>
